//
//  ViewController.m
//  AppSettingDemo
//
//  Created by Justsoso on 16/3/16.
//  Copyright © 2016年 Justsoso. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
@property (weak, nonatomic) IBOutlet UILabel *passworeLabel;
@property (weak, nonatomic) IBOutlet UILabel *protocolLabel;
@property (weak, nonatomic) IBOutlet UILabel *wrapLabel;
@property (weak, nonatomic) IBOutlet UILabel *wrapSpeedLabel;

@property (weak, nonatomic) IBOutlet UILabel *favoriteTeaLabel;
@property (weak, nonatomic) IBOutlet UILabel *favoriteCandyLabel;
@property (weak, nonatomic) IBOutlet UILabel *favoriteGameLabel;
@property (weak, nonatomic) IBOutlet UILabel *favoriteExcuseLabel;
@property (weak, nonatomic) IBOutlet UILabel *favoriteSinLabel;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self updateInfo];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateInfo) name:UIApplicationWillEnterForegroundNotification object:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [self updateInfo];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)updateInfo
{
    NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
    
    self.usernameLabel.text = [d valueForKey:@"username"];
    self.passworeLabel.text = [d valueForKey:@"password"];
    self.protocolLabel.text = [d valueForKey:@"protocol"];
    self.wrapLabel.text = [d boolForKey:@"wrap"]?@"开":@"关";
    self.wrapSpeedLabel.text = [NSString stringWithFormat:@"%@",[d valueForKey:@"wrapSpeed"]];
    self.favoriteTeaLabel.text = [d valueForKey:@"favoritTea"];
    self.favoriteCandyLabel.text = [d valueForKey:@"favoritCandy"];
    self.favoriteGameLabel.text = [d valueForKey:@"favoritGame"];
    self.favoriteExcuseLabel.text = [d valueForKey:@"favoritExcuse"];
    self.favoriteSinLabel.text = [d valueForKey:@"favoritSin"];
    
}

@end
